<!DOCTYPE html>
<html>
<head>
    <title>平台配置信息</title>
    <#include "/header.html">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <script src="${request.contextPath}/statics/plugins/layui/layui.all.js"></script>


</head>
<body>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title" style="padding: 0 20px;">
        <li class="layui-this">点击纪录配置</li>
        <li>IP运营商检测</li>
        <li>数据源配置</li>
        <li>阿里云配置</li>
        <li>阿里云同步</li>
    </ul>
    <div class="layui-tab-content" style="height: 100px;">
        <div class="layui-tab-item layui-show">
            <div class="panel">
                <form class="form-horizontal layui-form" action="" id="form1">
                    <div class="form-group">
                        <div class="col-sm-2 control-label">是否开启</div>
                        <div class="col-sm-10">
                            <input type="checkbox" name="zzz" lay-filter="switchTest" checked="checked" id="isopen" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">检测数量</div>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" autocomplete="off"  id="num" placeholder="检测数量">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">黑名单</div>
                        <div class="col-sm-10">

                            <textarea type="text" style="height: 150px;resize: none;"  required  id="blacklist"  placeholder="请输入黑名单" autocomplete="off" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label"></div>
                        <div class="col-sm-10">
                            <div class="alert alert-warning" role="alert">多个字段请换行，每行只能放一个字段</div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-2 control-label"></div>
                        <div class="col-sm-10">
                            <div class="layui-btn" id="btnconfirm">保存</div>
                        </div>

                    </div>

                </form>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="panel">
                <form class="form-horizontal layui-form" action="" id="form2">
                    <div class="form-group">
                        <div class="col-sm-2 control-label">是否开启</div>
                        <div class="col-sm-10">
                            <input type="checkbox" name="zzz" lay-filter="switchTest" checked="checked" id="isopen2" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">检测数量</div>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" autocomplete="off"  id="num2" placeholder="检测数量">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">关键字</div>
                        <div class="col-sm-10">
                            <textarea type="text" style="height: 150px;resize: none;" required  id="keyword2" placeholder="请输入关键字" autocomplete="off" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">白名单</div>
                        <div class="col-sm-10">

                            <textarea type="text" style="height: 150px;resize: none;"  required  id="whitelist2"  placeholder="请输入白名单" autocomplete="off" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label"></div>
                        <div class="col-sm-10">
                            <div class="alert alert-warning" role="alert">多个字段请换行，每行只能放一个字段</div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-2 control-label"></div>
                        <div class="col-sm-10">
                            <div class="layui-btn" id="btnconfirm2">保存</div>
                        </div>

                    </div>

                </form>
            </div>
        </div>
        <div class="layui-tab-item">
            <#include "./sourceSetting.html">
        </div>
        <div class="layui-tab-item">
            <#include "./aliyunSetting.html">
        </div>
        <div class="layui-tab-item">
            <div class="layui-container " style="width: 100%;" >
                <div class="layui-row" style="margin-top: 10px;">
                    <div class="form-group">
                        <div class="col-sm-8">
                            同步阿里云负载均衡<div class="btn btn-primary" style="margin-left: 20px;" id="update_btn1"><i style="display: none" class="fa fa-spinner fa-spin"></i> 同步</div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="margin-top: 10px;">
                    <div class="form-group" >
                        <div class="col-sm-8">
                            同步阿里云域名信息<div class="btn btn-primary" style="margin-left: 20px;" id="update_btn2"><i style="display: none" class="fa fa-spinner fa-spin"></i> 同步</div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="margin-top: 10px;">
                    <div class="form-group" >
                        <div class="col-sm-8">
                            同步阿里云区域信息<div class="btn btn-primary" style="margin-left: 20px;" id="update_btn3"><i style="display: none" class="fa fa-spinner fa-spin"></i> 同步</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>






<script>
    var form = null;
    $(function() {
        form = layui.form;
        //点击纪录配置
        $('#btnconfirm').click(function(){
            var index = layer.load(2);
            var _array=$('#blacklist').val().split("\n");
            for (var i = _array.length - 1; i >= 0; i--) {
                if (!_array[i]) {
                    _array.splice(i, 1);
                }
            }
            var _data = {
                blacklist:_array,
                isEnable:$('#form1 .layui-form-switch em').html()=='开启'?1:0,
                limitNum:$('#num').val()
            }
            $.ajax({
                type: "POST",
                url: baseURL + "configure/saveClickConfig",
                contentType: "application/json",
                data:JSON.stringify(_data),
                success: function (r) {
                    if(r.code==0){
                        layer.msg('保存成功')
                    }
                    layer.close(index);
                }
            })
        })
        //IP运营商检测
        $('#btnconfirm2').click(function(){
            var index = layer.load(2);
            var _array=$('#whitelist2').val().split("\n");
            for (var i = _array.length - 1; i >= 0; i--) {
                if (!_array[i]) {
                    _array.splice(i, 1);
                }
            }
            var _array2=$('#keyword2').val().split("\n");
            for (var i = _array2.length - 1; i >= 0; i--) {
                if (!_array2[i]) {
                    _array2.splice(i, 1);
                }
            }
            var _data = {
                serverName:_array2,
                whitelist:_array,
                isEnable:$('#form2 .layui-form-switch em').html()=='开启'?1:0,
                limitNum:$('#num2').val()
            }
            $.ajax({
                type: "POST",
                url: baseURL + "configure/saveIpTestingConfig",
                contentType: "application/json",
                data:JSON.stringify(_data),
                success: function (r) {
                    layer.close(index);
                    if(r.code==0){
                        layer.msg('保存成功')
                    }
                }
            })
        });

        $.ajax({
            type: "POST",
            url: baseURL + "configure/getClickConfig",
            contentType: "application/json",
            success: function (r) {
                if (r.code == 0) {
                    //点击纪录配置
                    $('#num').val(r.result.configureJson.limitNum);
                    if(r.result.configureJson.isEnable==1){
                        $('#isopen').prop('checked','checked')
                    }else{
                        $('#isopen').removeAttr('checked')
                    }
                    form.render();
                    $('.layui-form-switch').css('width','55px')
                    var value = '';
                    if(r.result.configureJson.blacklist){
                        for(var i=0;i<r.result.configureJson.blacklist.length;i++){
                            value = value +r.result.configureJson.blacklist[i]+'\n'
                        }
                    }
                    $('#blacklist').val(value)

                    // IP运营商检测
                    $('#num2').val(r.result.ipTesting.limitNum);
                    if(r.result.ipTesting.isEnable==1){
                        $('#isopen2').prop('checked','checked')
                    }else{
                        $('#isopen2').removeAttr('checked')
                    }
                    form.render();
                    $('.layui-form-switch').css('width','55px')
                    var value = '';
                    if(r.result.ipTesting.serverName){
                        for(var i=0;i<r.result.ipTesting.serverName.length;i++){
                            value = value +r.result.ipTesting.serverName[i]+'\n'
                        }
                    }

                    $('#keyword2').val(value)
                    var value = '';
                    if(r.result.ipTesting.whitelist){
                        for(var i=0;i<r.result.ipTesting.whitelist.length;i++){
                            value = value +r.result.ipTesting.whitelist[i]+'\n'
                        }
                    }
                    $('#whitelist2').val(value)
                } else {
                    alert(r.msg);
                }
            }
        });




    //    同步阿里云负载均衡
        $('#update_btn1').click(function(){
            if(!$(this).attr('disabled')){
                $('#update_btn1').attr('disabled','disabled').find('.fa').show()
                $.ajax({
                    type: "POST",
                    url: baseURL + "aliyunSlb/syncSlbInfo",
                    contentType: "application/json",
                    success: function (r) {
                        if(r.code==0){
                            layer.msg('同步成功')
                        }else{
                            layer.msg('同步失败')
                        }
                        $('#update_btn1').attr('disabled',false).find('.fa').hide()
                    },
                    error:function(){
                        $('#update_btn1').attr('disabled',false).find('.fa').hide()
                    }
                })
            }
        })
    //    同步阿里云域名信息
        $('#update_btn2').click(function(){
            if(!$(this).attr('disabled')) {
                $('#update_btn2').attr('disabled', 'disabled').find('.fa').show()
                $.ajax({
                    type: "POST",
                    url: baseURL + "aliyunDomain/syncDomainInfo",
                    contentType: "application/json",
                    success: function (r) {
                        if (r.code == 0) {
                            layer.msg('同步成功')
                        } else {
                            layer.msg('同步失败')
                        }
                        $('#update_btn2').attr('disabled', false).find('.fa').hide()
                    },
                    error: function () {
                        $('#update_btn1').attr('disabled', false).find('.fa').hide()
                    }
                })
            }
        })
    //    同步阿里云区域信息
        $('#update_btn3').click(function(){
            if(!$(this).attr('disabled')) {
                $('#update_btn3').attr('disabled', 'disabled').find('.fa').show()
                $.ajax({
                    type: "POST",
                    url: baseURL + "aliyunSlb/syncSlbDescribeRegionsInfo",
                    contentType: "application/json",
                    success: function (r) {
                        if (r.code == 0) {
                            layer.msg('同步成功')
                        } else {
                            layer.msg('同步失败')
                        }
                        $('#update_btn3').attr('disabled', false).find('.fa').hide()
                    },
                    error: function () {
                        $('#update_btn3').attr('disabled', false).find('.fa').hide()
                    }
                })
            }
        })
    })
</script>


</body>
</html>